package com.chtw.vuedemo.service.impl;

import com.chtw.vuedemo.bean.Goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author chtw
 * @date 2020-10-05 12:58
 */
@Service
public class GoodServiceImpl {

    @Autowired
    private MongoTemplate mongo;


    public List<Goods> list(int page, boolean all) {
        if(all){
            return mongo.findAll(Goods.class);
        }
        Criteria criteria = new Criteria();
        Query query = new Query(criteria);
        query.limit(10);
        query.skip((long)((page - 1) * 10));
        return mongo.find(query, Goods.class);
    }
}
